home *** CD-ROM | disk | FTP | other *** search
-
- ***********
- Listing 3
-
- #include <stdio.h>
-
- typedef struct
- {
- char fname[25];
- char lname[25];
- } REC;
-
- main()
- {
- REC rec, *recptr;
- char charstr[25], *cptr;
- int i;
-
- /***********/
-
- strcpy(rec.fname, "Stanley");
- strcpy(rec.lname, "Cohen");
-
- recptr = &rec;
- cptr = recptr; /*** value of recptr is assigned to cptr
- NO cast ***/
-
- i = 0;;
- while( charstr[i++] = *cptr++); /*** pointer arithmetic
- on cptr ***/
-
- puts(charstr); /*** first name is output to screen
- ***/
-
- cptr = recptr;
-
- printf("\n\address pointed to by cptr -> %d", cptr);
- printf("\naddress pointed to by recptr -> %d", recptr);
-
- cptr++;
- recptr++;
-
- printf("\n\naddress pointed to by cptr -> %d", cptr);
- printf("\naddress pointed to by recptr -> %d", recptr);
-
- }
- **********
-
-